package com.qf.flash.ui.chat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.qf.flash.R;
import com.qf.flash.http.response.PlayConditinoResponse;
import com.qf.flash.ui.home.adapter.NumberItem;
import com.qf.flash.ui.home.adapter.TypeItem;
import com.qf.flashlib.adapter.RVAdapter;
import com.qf.flashlib.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ModifyTeamInformationActivity extends BaseActivity {
    @BindView(R.id.tv_top_back)
    TextView tvTopBack;
    @BindView(R.id.tv_top_title)
    TextView tvTopTitle;
    @BindView(R.id.rv_type)
    RecyclerView rvType;
    @BindView(R.id.rv_count)
    RecyclerView rvCount;
    @BindView(R.id.rv_content)
    RecyclerView rvContent;


    private RVAdapter<Object> mAdapter;
    private RVAdapter<PlayConditinoResponse.ThemesBean> mTypeAdapter;
    private RVAdapter<String> mNumberAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_modify_my_team;
    }

    @Override
    protected void initViewAndData() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);// 设置默认键盘不弹出

        tvTopTitle.setText("修改组队信息");
        mAdapter = new RVAdapter<>(new GroupModifyBottomItem());
        List<Object> datas = mAdapter.getDatas();
        datas.add(new Object());
        datas.add(new Object());
        datas.add(new Object());
        datas.add(new Object());
        datas.add(new Object());
        datas.add(new Object());
        rvContent.setLayoutManager(new LinearLayoutManager(this));
        rvContent.setAdapter(mAdapter);
        rvContent.setHasFixedSize(true);
        rvContent.setNestedScrollingEnabled(false);

        initRvType();
        initRvNumber();
    }

    private void initRvNumber() {
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvCount.setLayoutManager(manager);
        mNumberAdapter = new RVAdapter<>(new NumberItem());
        mNumberAdapter.setOnItemClickListener(new RVAdapter.OnItemClickListener() {
            @Override
            public void onItemClick( View view, int position) {
                mNumberAdapter.setSingleChosenPosition(position);
                mNumberAdapter.notifyDataSetChanged();
            }
        });
        rvCount.setAdapter(mNumberAdapter);
        setNumberTestData();
    }

    private void initRvType() {
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvType.setLayoutManager(manager);
        mTypeAdapter = new RVAdapter<>(new TypeItem());
        rvType.setAdapter(mTypeAdapter);
        mTypeAdapter.setOnItemClickListener(new RVAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                mTypeAdapter.setSingleChosenPosition(position);
                mTypeAdapter.notifyDataSetChanged();
            }
        });
        setTypeTestData();
    }

    private void setTypeTestData() {
        List<String> data = new ArrayList<>();
        data.add("全部");
        data.add("武侠");
        data.add("爱情");
        data.add("都市");
        data.add("家庭");
        data.add("学生");
        data.add("社会社会");
        data.add("警匪");
        data.add("侠盗");
        data.add("110");
        mTypeAdapter.setSingleChosenPosition(0);
//        mTypeAdapter.setDatas(data);
    }

    private void setNumberTestData() {
        List<String> data = new ArrayList<>();
        data.add("全部");
        data.add("1");
        data.add("2");
        data.add("3");
        data.add("4");
        data.add("5");
        data.add("6");
        data.add("7");
        data.add("8");
        data.add("9");
        mNumberAdapter.setSingleChosenPosition(0);
        mNumberAdapter.setDatas(data);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.tv_top_back)
    public void onViewClicked() {
        finish();
    }


    public static void start(Activity activity) {
        Intent intent = new Intent(activity, ModifyTeamInformationActivity.class);
        activity.startActivity(intent);
    }
}
